Repository navigation
ddl: fix erwin DDL import + scope SQL DDL export to one subject area - #66
Merged
Merged
Conversation
…import) Importing Modelith's SQL DDL into erwin aborted with 'java.lang.IllegalArgumentException: Cannot add the same Attribute to Key' on the first table whose PRIMARY KEY listed the same column twice (seen in real erwin-imported models, where a pk key group can carry a duplicated member). The fatal killed the whole import at that table. - De-dupe key-column lists order-preservingly: PK members, business-key fallback, and FK child columns. No more PRIMARY KEY (col, col) / FOREIGN KEY (col, col). - Default a FK's referenced columns to the PARENT's primary key when the relationship doesn't name them, so REFERENCES points at a real key. erwin otherwise drops the FK with 'there is not a primary or unique key in table <parent> that contains column ...' (a warning, not fatal). A parent with NO primary key at all still can't receive a FK -- that is a modelling condition the emitter cannot invent around. Tests: a duplicated-PK-member model emits the column once; an FK with no named parent columns REFERENCES the parent PK. 432 passed.
…rea FKs) Like erwin's own subject-area export, a scoped SQL DDL export now emits ONLY the selected subject area's tables. A relationship with an end outside the area is dropped and the out-of-area neighbour is NOT emitted as a stub table — the neighbours already exist in the target erwin model, so the slice imports as an independent model and the cross-area FKs are re-established there by hand. The FK COLUMN stays on the in-area table as an ordinary attribute. - build_tables(model, adapter, subject_area=None): filters to the area's logical entities; the existing child/parent lookup already drops a relationship whose other end is out of scope. - emit_sql_ddl(..., subject_area=None) threads it through. - CLI: mdl export sql --subject-area/-s <name|id>. - API: /api/export/sql?subject_area=<id>. - Canvas: the Export menu scopes the SQL DDL link to a single active subject-area filter, same as erwin (the '. filtered area only' note shows for both). Mermaid/DBML/CSV are unchanged (they pass no subject_area -> whole model). Rebuilt canvas bundle. Tests: scoped export emits only in-area tables, keeps within-area FKs, drops cross-area FKs with no stub. 433 passed; canvas tsc clean, Vitest 55 passed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two commits, both on the SQL-DDL interchange path that you're using to get models into erwin.
1. Fix the fatal that aborted erwin's DDL import
Exporting Modelith SQL DDL and running erwin's "Import from External Format" (DdlScript bridge) aborted with:
erwin was handed a
PRIMARY KEYlisting the same column twice (apkkey group with a duplicated member, seen in erwin-imported models), and that one fatal killed the whole import.PRIMARY KEY (col, col)/FOREIGN KEY (col, col).REFERENCESpoints at a real key.2. Scope the SQL DDL export to one subject area (no stubs, drop cross-area FKs)
Just like erwin's own subject-area export, a scoped SQL DDL export now emits only the selected area's tables.
account) is not emitted as a stub table. The neighbours already exist in the target erwin mart, so the slice imports as an independent model and you re-establish the cross-area FKs by hand after merge. The FK column stays on the in-area table as an ordinary attribute.mdl export sql --subject-area/-s <name|id>,/api/export/sql?subject_area=<id>, and the canvas Export menu scopes the SQL DDL link to a single active subject-area filter (same· filtered area onlynote as erwin).This supersedes the "give each stub a PK so the FK attaches" idea from the other session's analysis — per your workflow, you want no stubs and will wire cross-area FKs yourself in the target model.
Verified
Whole-model vs scoped, live:
Only
trade(noaccountstub), cross-areaREFERENCES accountdropped,account_idcolumn retained.Mermaid/DBML/CSV unchanged (whole-model). 433 passed, ruff clean; canvas tsc clean, Vitest 55 passed; canvas bundle rebuilt.
Honest limit
Not verified against real erwin here (no erwin in CI); built to the exact fatal in the import log. The real test is re-exporting DDL and re-running the erwin DdlScript import on Windows.